#include <iostream>
#include <algorithm>

using namespace std;

const int radix = 12;
const int T = 10;

int checkRadix(long long n, int rad) {
    int bit = 0;
    while (n) {
        int r = n % rad;
        bit |= 1 << r;
        n /= rad;
    }
    return (1 << rad) - 1 == bit;
}

int check(long long n) {
    for (int i = radix - 1; i >= 3; i--) {
        if (!checkRadix(n, i)) {
            return 0;
        }
    }

    return 1;
}

int main()
{
    int dec[] = {1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    int t = 0;
    long long ans = 0;
    do {
        long long n = 0;
        long long twe = 1LL;
        for (int i = 0; i < radix; i++) {
            n += dec[radix - i - 1] * twe;
            twe *= radix;
        }

        if (check(n)) {
            t++;
            cout << t << " " << n << endl;
            ans += n;
            if (t == T) {
                break;
            }
        }
    } while(next_permutation(dec, dec + radix));
    cout << "ans: " << ans << endl;
    return 0;
}
